package com.food.eat.util;

import org.apache.poi.ss.usermodel.*;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

public class ExcelParser {
    public static List<Map<String, String>> readExcel(String filePath) {
        List<Map<String, String>> dataList = new ArrayList<>();
        try (FileInputStream fis = new FileInputStream(filePath);
             Workbook workbook = WorkbookFactory.create(fis)) {
            Sheet sheet = workbook.getSheetAt(0); // 第一个工作表
            Row headerRow = sheet.getRow(0);     // 表头行（物料编码、物料名称等）

            // 遍历数据行（从第二行开始）
            for (int i = 1; i <= sheet.getLastRowNum(); i++) {
                Row row = sheet.getRow(i);
                if (row == null) continue;

                Map<String, String> data = new HashMap<>();
                data.put("账号", row.getCell(0).getStringCellValue());
                data.put("密码", row.getCell(1).getStringCellValue());
//                data.put("物料名称", row.getCell(1).getStringCellValue());
//                data.put("供应商名称", row.getCell(2).getStringCellValue());
//                data.put("供应商地址", row.getCell(3).getStringCellValue());

                dataList.add(data);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataList;
    }
}
